<template>
  <div class="guns-layout">
    <div class="guns-layout-content">
      <div class="guns-layout">
        <div class="guns-layout-content-application">
          <div class="content-mian">
            <div class="content-mian-header">
              <div class="header-content">
                <div class="header-content-left">
                  <a-space :size="16">
                    <a-input
                      v-model:value="where.searchText.name"
                      placeholder="姓名"
                      @pressEnter="reload"
                      class="search-input"
                    >

                      <template #prefix>
                        <icon-font iconClass="icon-opt-search"></icon-font>
                      </template>
                    </a-input>
                    <a-input
                        v-model:value="where.searchText.inNo"
                        placeholder="病案号"
                        @pressEnter="reload"
                        class="search-input"
                    >
                    </a-input>
                    <drop-down
                        :list="diseaseList"
                        dropName="病种"
                        ref="diseaseRef"
                        keyValue="dictCode"
                        keyName="dictName"
                        @dropClick="diseaseChange"
                    />
                    <a-button class="border-radius" @click="clear">重置</a-button>
                  </a-space>
                </div>
                <div class="header-content-right">
                  <a-space :size="16">

                    <a-dropdown>
                      <template #overlay>
                        <a-menu @click="moreClick">
                          <a-menu-item key="1">
                            <icon-font iconClass="icon-opt-zidingyilie" color="#60666b"></icon-font>
                            <span>自定义列</span>
                          </a-menu-item>
<!--                          <div v-permission="['DELETE_POSITION']">
                            <a-menu-item key="2">
                              <icon-font iconClass="icon-opt-shanchu" color="#60666b"></icon-font>
                              <span>批量删除</span>
                            </a-menu-item>
                          </div>-->
                        </a-menu>
                      </template>
                      <a-button class="border-radius">
                        更多
                        <small-dash-outlined />
                      </a-button>
                    </a-dropdown>
                  </a-space>
                </div>
              </div>
            </div>
            <div class="content-mian-body">
              <div class="table-content">
                <common-table :columns="columns" :where="where" rowId="positionId" ref="tableRef" url="/patients/reportPage">
                  <template #bodyCell="{ column, record }">
                    <template v-if="column.dataIndex == 'inNo'">
                      <a @click="openAddEdit(record)">{{ record.inNo }}</a>
                    </template>
                  </template>
                </common-table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 自定义列 -->
    <Custom
      v-model:visible="isShowCustom"
      v-if="isShowCustom"
      :data="columns"
      @done="val => (columns = val)"
      :fieldBusinessCode="fieldBusinessCode"
    />

    <!-- 新增编辑弹框 -->
    <ReportView v-model:visible="showEdit" v-if="showEdit" :data="current" @done="reload" />
  </div>
</template>

<script setup name="Position">
import { SysDictApi } from './api/SysDictApi';
import {ref, createVNode, onMounted, onBeforeMount,reactive} from 'vue';
import ReportView from './components/report-view.vue';
import { CustomApi } from '@/components/common/Custom/api/CustomApi';
// 表格配置
const columns = ref([
  {
    key: 'index',
    title: '序号',
    width: 48,
    align: 'center',
    isShow: true,
    hideInSetting: true
  },
  {
    dataIndex: 'inNo',
    title: '病案号',
    width: 80,
    isShow: true
  },
  {
    dataIndex: 'name',
    title: '患者姓名',
    ellipsis: true,
    width: 100,
    isShow: true,

  },
  {
    dataIndex: 'diseaseName',
    title: '疾病类型',
    ellipsis: true,
    width: 150,
    isShow: true,

  },

  {
    dataIndex: 'escalationName',
    title: '上报账户',
    ellipsis: true,
    width: 100,
    isShow: true
  },
  {
    dataIndex: 'outDate',
    title: '出院时间',
    width: 150,
    isShow: true
  },
  {
    dataIndex: 'status',
    title: '上报状态',
    width: 80,
    isShow: true,
    customRender:function (t,r,index) {
      if(t.value == 0){
        return '未上报'
      }
      if(t.value == 1){
        return '草稿'
      }
      if(t.value == 2){
        return '待审核'
      }
      if(t.value == 3){
        return '已上报'
      }
      if(t.value == 4){
        return '退回'
      }
      if(t.value == 5){
        return '废弃'
      }
    }
  },
  {
    dataIndex: 'escalationDate',
    title: '上报时间',
    width: 150,
    isShow: true
  },
  {
    dataIndex: 'reason',
    title: '驳回/失败原因',
    width: 200,
    isShow: true
  }
]);
// ref
const tableRef = ref(null);
const diseaseRef = ref(null);
const diseaseList = ref(null);

// 搜索条件
const where = ref({
  searchText: {}
});
// 是否显示自定义列
const isShowCustom = ref(false);
// 当前行数据
const current = ref(null);
// 是否显示新增编辑弹框
const showEdit = ref(false);
// 业务标识的编码
const fieldBusinessCode = ref('PATIENT_TABLE');

onBeforeMount(() => {
   getDictData();
});
onMounted(() => {
  getColumnData();
 // getDictData();
});

const getDictData = () => {


  SysDictApi.list({ dictTypeId: '1813510904349069313' }).then(res => {
    diseaseList.value = res.data;
  });
};

// 获取表格配置
const getColumnData = () => {
  CustomApi.getUserConfig({ fieldBusinessCode: fieldBusinessCode.value }).then(res => {
    if (res.tableWidthJson) {
      columns.value = JSON.parse(res.tableWidthJson);
    }
  });
};

// 更多点击
const moreClick = ({ key }) => {
  if (key == '1') {
    isShowCustom.value = true;
  } else if (key == '2') {
    batchDelete();
  }
};
const diseaseChange = val => {
  where.value.diseaseCode = val;
  reload();
};
// 点击搜索
const reload = () => {
  tableRef.value.reload();
};

// 清除搜索条件
const clear = () => {
  where.value.searchText = '';
  diseaseRef.value.changeDropname('病种');
  reload();
};

// 新增编辑点击
const openAddEdit = record => {

  for(let i = 0; i < diseaseList.value.length; i ++) {
    if (record.diseaseCode ==  diseaseList.value[i].dictCode) {
      record["diseaseName"]=diseaseList.value[i].dictName
    }
  }
  current.value = record;
  showEdit.value = true;
};



</script>

<style scoped lang="less"></style>
